<?php
class Mnews extends CI_Model {
	function __construct() {
		parent::__construct ();
	}
	
	function showNum (){
		$this->db->where ( 'show', 'T' );
		return $this->db->count_all_results ( 'news' );
	}
	
	function addNews($data) {
		$data ['updateTime'] = date ( "Y/m/d H:i:s", time () );
		$this->db->insert ( 'news', $data );
		return $this->db->insert_id ();
	}
	
	function getNewsList($page, $num) {
		$this->db->select ( 'id,title,show,updateTime,updatePerson' );
		$this->db->where ( 'class', 'N' );
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( $num, $page );
		$query = $this->db->get ( 'news' );
		return $query->result_array ();
	}
	
	function getShowAct($page, $num) {
		$this->db->select ( 'id,title,newsImage' );
		$this->db->where ( 'class', 'A' );
		$this->db->where ( 'show', 'T' );
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( $num, $page );
		$query = $this->db->get ( 'news' );
		return $query->result_array ();
	}
	
	
	function getNewsListforShow() {
		$this->db->select ( 'id,newsImage,class' );
		$this->db->where ( 'show', 'T' );
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( 5 );
		$query = $this->db->get ( 'news' );
		return $query->result_array ();
	}
	
	function getNewsNum() {
		$this->db->where ( 'class', 'N' );
		return $this->db->count_all_results ( 'news' );
	}
	
	function getActivityList($page, $num) {
		$this->db->select ( 'id,title,show,updateTime,updatePerson' );
		$this->db->where ( 'class', 'A' );
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( $num, $page );
		$query = $this->db->get ( 'news' );
		return $query->result_array ();
	}
	
	function getActivityNum() {
		$this->db->where ( 'class', 'A' );
		return $this->db->count_all_results ( 'news' );
	}
	
	function getCardPostList($page, $num) {
		$this->db->select ( 'id,title,show,updateTime,updatePerson' );
		$this->db->where ( 'class', 'C' );
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( $num, $page );
		$query = $this->db->get ( 'news' );
		return $query->result_array ();
	}
	
	function getCardPostNum() {
		$this->db->where ( 'class', 'C' );
		return $this->db->count_all_results ( 'news' );
	}
	
	function getItembyIdClass($id, $class) {
		$this->db->where ( 'id', $id );
		$this->db->where ( 'class', $class );
		$query = $this->db->get ( 'news' );
		if ($query->num_rows () > 0) {
			return $query->row_array ();
		} else
			return NULL;
	}
	
	function delItembyIdClass($id, $class) {
		$this->db->where ( 'id', $id );
		$this->db->where ( 'class', $class );
		$this->db->delete ( 'news' );
		if ($this->db->affected_rows () > 0)
			return TRUE;
		else
			return FALSE;
	}
	
	function updateNews($data) {
		$data ['updateTime'] = date ( "Y/m/d H:i:s", time () );
		$this->db->where ( 'id', $data ['id'] );
		$this->db->update ( 'news', $data );
		if ($this->db->affected_rows () > 0)
			return TRUE;
		else
			return FALSE;
	}
	
	function getRelatedList() {
		$this->db->select ( 'id,title,class' );
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( 10 );
		$query = $this->db->get ( 'news' );
		return $query->result_array ();
	}

}